#include "HufArc.h"

int _CharInBits (unsigned char * Dest,const unsigned char * Source, const unsigned char ** tables, str_inf * inf)
{
	size_t u_bits = 8;
	if (inf->u_bits == 0)
	u_bits = 8;
	else
		u_bits = inf->u_bits;
	while (inf->pos < 8)
	{
		if (u_bits == 0)
			u_bits = 8;
		while (u_bits != 0)
		{
				if (inf->ind_bits < strlen((char*)tables[Source[inf->ind_char]]))
					if (tables[Source[inf->ind_char]][inf->ind_bits] == '1')
					{
						Dest[inf->pos] |= (__MARKER << (u_bits));
						u_bits --;
						inf->ind_bits ++;
					} else
					{
						u_bits --;
						inf->ind_bits ++;
					}
				else 
				{
					inf->ind_bits = 0;
					if (inf->ind_char < inf->len - 1)
						inf->ind_char ++;
					else 
					{
						//inf->pos ++;
						//inf->ind_char = 0;
						//inf->ind_bits = 0;
						inf->u_bits =u_bits;
						return 0;
					}
				} 
		}
		inf->pos++;
	}
	inf->u_bits = u_bits;
	if ((inf->ind_char == (inf->len-1)) && (inf->ind_bits == (strlen((char*)tables[Source[inf->ind_char]]) - 1)) && (u_bits = 0))
	{
		inf->ind_char = 0;
		inf->ind_bits = 0;
		return 1;
	}
	else 
	{ 
		return 2;
	}
}


